package main

import (
	"fmt"
	"net"
	"strconv"
)

func Read(conn net.Conn) string {
	lengthByte := make([]byte, 5)
	conn.Read(lengthByte)
	length, _ := strconv.Atoi(string(lengthByte))
	ctx := make([]byte, length)
	conn.Read(ctx)
	return string(ctx)
}

func main() {
	listener, err := net.Listen("tcp", "127.0.0.1:8989")
	if err != nil {
		fmt.Println(err)
		return
	}

	conn, err := listener.Accept()
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(Read(conn))

	conn.Close()

	listener.Close()
}
